//
//  YXYUserProfileViewController.m
//  Topit
//
//  Created by dllo on 15/12/19.
//  Copyright © 2015年 YXY. All rights reserved.
//

#import "YXYUserProfileViewController.h"

@interface YXYUserProfileViewController ()
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UILabel *userName;
@end

@implementation YXYUserProfileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUserProfile];
    // Do any additional setup after loading the view.
}

- (void)setUserProfile {
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSMutableDictionary *users = [user objectForKey:@"user"];

    UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:myView.bounds];
    imageView.image = [UIImage imageNamed:@"Background"];
    [myView addSubview:imageView];
    [imageView release];
    
    UIImageView *idImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.width / 2 - 40, 80, 80, 80)];
    idImage.layer.cornerRadius = 40;
    idImage.clipsToBounds = YES;
    
    UILabel *idName = [[UILabel alloc] initWithFrame:CGRectMake(0, idImage.bottom + 10, self.view.width, 20)];
    idName.textAlignment = 1;
    
    if ([users count] == 0) {
        idImage.image = [UIImage imageNamed:@"avatar"];
        idName.text = @"Topit";
    }else {
        [idImage sd_setImageWithURL:[NSURL URLWithString:[users valueForKey:@"image"]]];
        idName.text = [users valueForKey:@"name"];
    }
    
    UIButton *cancel = [UIButton buttonWithType:UIButtonTypeSystem];
    cancel.frame = CGRectMake((self.view.width / 2) - 25, idName.bottom + 300, 50, 30);
    [cancel setTitle:@"注销" forState:UIControlStateNormal];
    [cancel addTarget:self action:@selector(cancelDidPress:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:myView];
    [myView addSubview:idImage];
    [idImage release];
    [myView addSubview:idName];
    [idName release];
    [myView addSubview:cancel];
    

}

- (void)cancelDidPress:(UIButton *)sender {
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user removeObjectForKey:@"user"];
    [ProgressHUD showSuccess:@"取消成功"];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
